import axios from 'axios'
import router from '../router/index'
const instance = axios.create({
    baseURL: 'http://81.68.251.102:7878',
    // timeout: 20000
})

// 请求拦截【instance.interceptors.request.use(cb, cb)】
instance.interceptors.request.use(config => {
    let token = localStorage.getItem("token")
    // config.headers.token = "xxxx"
    // if (token) {
    //     config.headers = config.headers || {};
    //     config.headers["Authorization"] = token;
    //     console.log(1);
    // }
    return config;
}, err => {
    return Promise.reject(err)
})

// 响应拦截【instance.interceptors.response.use(cb, cb)】
instance.interceptors.response.use(result => {
    if(result.data.msg=="请先登录!"){
        router.push('/')
    }
    return result.data;
}, err => {
    return Promise.reject(err)
})

export default instance;